package com.qtt.app.service.impl;

import com.qtt.app.entity.AppInstitution;
import com.qtt.app.mapper.AppCourseMapper;
import com.qtt.app.mapper.AppInstitutionMapper;
import com.qtt.app.service.AppInstitutionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AppInstitutionServiceImpl implements AppInstitutionService {

    @Autowired
    AppInstitutionMapper appInstitutionMapper;
    @Autowired
    AppCourseMapper appCourseMapper;

    @Override
    public Integer addInstitution(AppInstitution entity) {
        int b=appInstitutionMapper.insert(entity);
        Integer b1 = new Integer(b);
        return b1;
    }

    @Override
    public int addInstitution2(AppInstitution entity) {
        int b=appInstitutionMapper.insert(entity);
        return b;
    }

    @Override
    public AppInstitution getById(Integer institutionId) {
        AppInstitution appInstitutionEntity = appInstitutionMapper.selectByPrimaryKey(institutionId);
        return appInstitutionEntity;
    }

    @Override
    public Boolean updateById(Integer id, AppInstitution entity) {
        Boolean b = appInstitutionMapper.updateById(id,entity);
        return b;
    }

    //根据课程id查找其对应的机构信息
    @Override
    public AppInstitution getInstByCourse(String generalId) {
        Integer institutionId = appCourseMapper.getInstitutionIdByCourse(generalId);
        if(institutionId==null){
            return null;
        }
        AppInstitution appInstitutionEntity = appInstitutionMapper.selectByPrimaryKey(institutionId);
        return appInstitutionEntity;
    }

    @Override
    public List<AppInstitution> getRecommendCourse() {
        List<AppInstitution> entities = appInstitutionMapper.getRecommendCourse();
        return entities;
    }

    @Override
    public List<AppInstitution> listAll() {
        List<AppInstitution> entities = appInstitutionMapper.getAll();
        return entities;
    }
}
